String.prototype.string = function(len){var s = '', i = 0; while (i++ < len) { s += this; } return s;};
String.prototype.lpad = function(len){return "0".string(len - this.length) + this;};
Number.prototype.lpad = function(len){return this.toString().lpad(len);};

function getStrDate(day) {
	var resultDay = new Date();
	if (day != 0) {
		resultDay = new Date( Date.parse( resultDay ) + (day * 1000 * 60 * 60 * 24) );
	}
	return resultDay.getFullYear()+'-'+(resultDay.getMonth()+1).lpad(2)+'-'+resultDay.getDate().lpad(2);
}

/**
 * 쿠키 설정하기 
 * @param string 쿠키명
 * @param string 쿠키값
 * @param int 유효일
 */
function setCookie(cName, cValue, cDate) {
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + cDate );
	document.cookie = cName + "=" + escape( cValue ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

/**
 * 쿠기 가져오기 
 * @param string 쿠키명
 */
function getCookie(cName) {
	var nameOfCookie = cName + "=";
	var x = 0;
	while ( x <= document.cookie.length ) {
		var y = (x+nameOfCookie.length);
		if ( document.cookie.substring( x, y ) == nameOfCookie ) {
			if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
			endOfCookie = document.cookie.length;
			return unescape( document.cookie.substring( y, endOfCookie ) );
		}

		x = document.cookie.indexOf( " ", x ) + 1;
		if ( x == 0 ) {
			break;
		}
	}
	return "";
}

/**
 * 현재 창을 컨텐츠 크기에 맞게 조절
 */
function resizePopup(jqueryObj) {
	setTimeout(function() {
		var Dwidth = parseInt($("div:first").width());
		var Dheight = parseInt($("div:first").height());
		if (jqueryObj != undefined) {
			alert(jqueryObj);
			Dwidth = parseInt(jqueryObj.width());
			Dheight = parseInt(jqueryObj.height());
			
		}
		var divEl = document.createElement("div");
		divEl.style.position = "absolute";
		divEl.style.left = "0px";
		divEl.style.top = "0px";
		divEl.style.width = "100%";
		divEl.style.height = "100%";
		
		document.body.appendChild(divEl);
		
		window.resizeBy(Dwidth-divEl.offsetWidth, Dheight-divEl.offsetHeight);
		document.body.removeChild(divEl);
	},200);
}


/**
 * 창을 화면 가운데로 띄어준다.
 * @param string url
 * @param int 창의 가로 길이
 * @param int 창의 세로 길이
 */
function openPopup(url, width, height, frameName) {
	var fName = frameName != '' ? frameName : 'popup';
	var popWidth = width;  // 창의 가로 길이
	var popHeight = height;  // 창의 세로 길이
	var leftPos = Math.ceil((window.screen.width - popWidth)/2);
	var topPos = Math.ceil((window.screen.height - popHeight)/2);
	window.open(url, fName,"top="+topPos+",left="+leftPos+",width="+popWidth+",height="+popHeight+",scrollbars=yes");
}
